//
//  MoreDesignView.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/25.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "MoreDesignView.h"

@interface MoreDesignView()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *headImage;
@property (nonatomic, strong) UILabel *nameLabel;

@end

@implementation MoreDesignView

- (void)setDesignModel:(DesignModel *)designModel {
    _designModel = designModel;
    
    if ([designModel.coverPics class] != [NSNull class]) {
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:designModel.coverPics[0]] placeholderImage:nil options:SDWebImageRetryFailed];
    }
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:designModel.userPic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.nameLabel.text = designModel.userName;
    self.titleLabel.text = designModel.proName;
    if ([designModel.isZan integerValue]) {
        [self.concernBtn setImage:ImageWithName(@"已点赞") forState:UIControlStateNormal];
        
    }else {
        [self.concernBtn setImage:ImageWithName(@"点赞") forState:UIControlStateNormal];
    }
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, ScreenX375(113))];
        self.imageView.layer.cornerRadius = ScreenX375(6);
        self.imageView.image = ImageWithName(@"16");
        self.imageView.clipsToBounds = YES;
        self.imageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:self.imageView];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(123), frame.size.width, ScreenX375(16))];
        self.titleLabel.font = Kfont(14);
        self.titleLabel.textColor = [UIColor blackColor];
        self.titleLabel.text = @"多层立体造型拼接牛仔风";
        [self addSubview:self.titleLabel];
        
        self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, ScreenX375(147), ScreenX375(29), ScreenX375(29))];
        self.headImage.layer.cornerRadius = ScreenX375(14.5);
        self.headImage.image = ImageWithName(@"头像1");
        self.headImage.clipsToBounds = YES;
        [self addSubview:self.headImage];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(34), ScreenX375(147), ScreenX375(100), ScreenX375(29))];
        self.nameLabel.textColor = REXADECIMALCOLOR(@"#666666");
        self.nameLabel.text = @"舒情123";
        self.nameLabel.font = Kfont(14);
        [self addSubview:self.nameLabel];
        
        UIButton *detailBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        [detailBtn addTarget:self action:@selector(detailAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:detailBtn];
        
        self.concernBtn = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width - ScreenX375(17), ScreenX375(150), ScreenX375(17), ScreenX375(17))];
        [self.concernBtn setImage:ImageWithName(@"点赞") forState:UIControlStateNormal];
        [self.concernBtn addTarget:self action:@selector(concernAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.concernBtn];
    }
    return self;
}

- (void)concernAction {
    if (_concernClick) {
        _concernClick();
    }
}

- (void)detailAction {
    if (_detailClick) {
        _detailClick();
    }
}

@end

@implementation DesignModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}

@end
